package com.spring.test.common.service;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spring.test.common.util.CommonUtil;
import com.spring.test.common.vo.TestOrderVo;
import com.spring.test.common.vo.TestUserVo;
import com.spring.test.mybatis.mapper.TestOrderMapper;
import com.spring.test.mybatis.mapper.TestUserMapper;
import com.spring.test.mybatis.model.TestOrder;
import com.spring.test.mybatis.model.TestOrderExample;
import com.spring.test.mybatis.model.TestUser;

@Service("com.pfm.jdh.common.service.VoService")
public class VoService extends CommonService {
	
	@Autowired(required=false)
	private TestUserMapper testUserMapper;
	@Autowired(required=false)
	private TestOrderMapper testOrderMapper;
	
	public TestUserVo getTestUserVo(String id) {
		
		//TestUserVo setting!!
		TestUser testUser = (TestUser)testUserMapper.selectByPrimaryKey(id);
		
		TestUserVo testUserVo = new TestUserVo();
		testUserVo = (TestUserVo)CommonUtil.getModelToVo(testUser, testUserVo);
		
		/*
		testUserVo.setId(testUser.getId());
		testUserVo.setAge(testUser.getAge());
		testUserVo.setName(testUser.getName());
		testUserVo.setCreateDate(testUser.getCreateDate());
		*/
		
		//TestOrderVo setting!!
		TestOrderExample testOrderExample = new TestOrderExample();
		TestOrderExample.Criteria testOrderrCriteria = testOrderExample.createCriteria();
		testOrderrCriteria.andUserIdEqualTo(testUser.getId());
		
		List<TestOrderVo> testOrderVoList = new ArrayList<TestOrderVo>();
		
		List<TestOrder> testOrderList = (ArrayList<TestOrder>)testOrderMapper.selectByExample(testOrderExample);
		TestOrder testOrder = null;
		
		for(int i=0; i<testOrderList.size(); i++) {
			testOrder = (TestOrder)testOrderList.get(i);
			TestOrderVo testOrderVo = new TestOrderVo();
			testOrderVo = (TestOrderVo)CommonUtil.getModelToVo(testOrder, testOrderVo);
			
			/*
			testOrderVo.setId(testOrder.getId());
			testOrderVo.setUserId(testOrder.getUserId());
			testOrderVo.setName(testOrder.getName());
			testOrderVo.setCreateDate(testOrder.getCreateDate());
			*/
			
			testOrderVo.setTestUserVo(testUserVo);
			
			testOrderVoList.add(testOrderVo);
		}
		
		testUserVo.setTestOrderVoList(testOrderVoList);
		
		return testUserVo;
	}
}